#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
using namespace std;

class Solution01 {
public:
    int singleNumber(vector<int>& nums) {
        int ret = 0;
        for (int i = 0; i <= 31; i++) {
            // 将每一位取下来，分别相加，然后模三
            int sumbit = 0;
            for (auto e : nums) {
                sumbit += ((e >> i) & 1);
            }
            sumbit %= 3;
            int add = sumbit << i;
            ret |= add;
        }
        return ret;
    }
};

class Solution02 {
public:
    vector<int> missingTwo(vector<int>& nums) {
        // 从1下标开始到n
        int len = nums.size() + 2;
        int xorx = 0;
        for (int i = 1; i <= len; i++)
            xorx ^= i;

        for (auto e : nums)
            xorx ^= e;

        int x1 = 0, y1 = 0;
        int lsb = (xorx == INT_MIN ? xorx : xorx & (-xorx));
        for (auto e : nums) {
            if (lsb & e)
                x1 ^= e;
            else
                y1 ^= e;
        }
        for (int i = 1; i <= len; i++) {
            if (lsb & i)
                x1 ^= i;
            else
                y1 ^= i;
        }
        return {x1, y1};
    }
};

class Solution03 {
public:
    string modifyString(string s) {
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '?') {
                // 将该字符给修改
                // 获取前后两个字符的数字
                int before = INT_MAX, after = INT_MAX;
                if (i > 0) before = s[i - 1] - 'a';
                if (i < s.size() - 1) after = s[i + 1] - 'a';
                if (before != INT_MAX && after != INT_MAX) {
                    int r = rand() % 26;
                    while (!(r != before && r != after)) r = rand() % 26;
                    s[i] = r + 'a';

                } else if (before != INT_MAX) {
                    int r = rand() % 26;
                    while (r == before) r = rand() % 26;
                    s[i] = r + 'a';

                } else {
                    int r = rand() % 26; 
                    while (r == after) r = rand() % 26;
                    s[i] = r + 'a';  

                }
            }
        }
        return s;
    }
};

class Solution04 {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {

        int cnt = 0, len = timeSeries.size();
        if (len == 1) return duration;
        for (int i = 0; i < len - 1; i++) {
            if (timeSeries[i] == timeSeries[i + 1])
                continue;
            if (timeSeries[i] + duration - 1 < timeSeries[i + 1])
                cnt += duration;
            else
                cnt += timeSeries[i + 1] - timeSeries[i];
        }
        cnt += duration;
        return cnt;
    }
};

class Solution05 {
public:
    string convert(string s, int numRows) {
        int d = numRows * 2 - 2;
        if (numRows == 1) return s;
        string ret;
        for (int i = 0; i < s.size(); i += d)
            ret += s[i];
        for (int i = 1; i < numRows - 1; i++) {
            // 一行一个循环
            int k = i, j = 0;
            for (; j * d - k + d < s.size(); j++) {
                ret += s[k + j * d];
                ret += s[j * d - k + d];
            }
            if (k + j * d < s.size()) ret += s[k + j * d];
        }
        for (int i = numRows - 1; i < s.size(); i += d)
            ret += s[i];
        return ret;
    }
};

class Solution06 {
public:
    string countAndSay(int n) {
        string s = "1";
        for (int i = 1; i < n; i++) {
            // 对 s 进行解释
            string ret;
            for (int right = 0, left = 0; right < s.size(); ) {
                while (right < s.size() && s[left] == s[right]) 
                    right++;
                int cnt = right - left;
                ret += cnt + '0';
                ret += s[left];
                left = right;
            }
            s = ret;
        }
        return s;
    }
};

int main() {


    return 0;
}